# 创建时间：2025/5/10 星期六 13:28
# 创建人：李德才
import pymysql

"""  修改和删除数据只是语句不一样，其他的都一样  """

conn = pymysql.connect(host='localhost', user='root', password='123456', database='archser', charset='utf8', port=3306)
cursor = conn.cursor()
try:
    sql = "insert into as_user(username,password) values(%s,%s)"

    """ 单条添加数据  """
    params = ('zhangsan', 20)
    cursor.execute(sql, params)
    """ 多条添加数据 """
    params = [('zhangsan1', 20), ('zhangsan1', 20)]
    cursor.executemany(sql, params)

    conn.commit()
except  Exception as e:
    print(e)
    conn.rollback()
cursor.close()
conn.close()
